package com.huan.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(filterName = "CharEncodingFilter",urlPatterns = {"/*"})
public class CharEncodingFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
        System.out.println(this.getClass().getName()+"init..........");
    }

    public void destroy() {
        System.out.println(this.getClass().getName()+"destroy..........");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        System.out.println(this.getClass().getName()+"................");
        //解决中文乱码问题
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        chain.doFilter(request, response);
    }
}
